﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;

namespace EAGL.data
{
    /// <summary>
    /// checks the schema of two tables if identical
    /// </summary>
    public class TableSchemaChecker
    {
        private ITable source;
        private ITable destination;

        private bool isIdentical()
        {
            IFields srcFields = source.Fields;
            IFields desFields = destination.Fields;

            int c1 = srcFields.FieldCount;
            int c2 = desFields.FieldCount;
            if (c1 != c2)
                return false;

            int i = 0;
            bool v = true;
            while (i < c1 && v)
            {
                IField sf = srcFields.get_Field(i);
                IField df = desFields.get_Field(i);
                v = (sf.Name == df.Name) && (sf.Type == df.Type);
                i++;
            }


            return v;
        }
        
        public TableSchemaChecker(ITable source, ITable destination)
        {
            this.source = source;
            this.destination = destination;
        }

        public bool IsIdentical
        {
            get { return isIdentical();}
        }
    }
}
